import java.util.Comparator;
import java.util.PriorityQueue;
import java.util.Queue;

/**
 * Created with IntelliJ IDEA.
 * Description:
 */
class Bigheap implements Comparator<Integer>{
    @Override
    public int compare(Integer o1, Integer o2) {
        return o2.compareTo(o1);
    }
}
public class Text {
    public static void main(String[] args) {
        Bigheap bigheap =new Bigheap();
        PriorityQueue<Integer> queue = new PriorityQueue<>(bigheap);
        queue.offer(12);
        queue.offer(11);
        System.out.println(queue.peek());

    }
    public static void main1(String[] args) {
        PriorityQueue<Integer> queue = new PriorityQueue<>();
        queue.offer(4);
        queue.offer(3);
        queue.offer(2);
        queue.offer(1);
        System.out.println(queue.size());
        System.out.println(queue.peek());
        System.out.println(queue.poll());
        System.out.println(queue.size());
        queue.clear();
        System.out.println(queue.isEmpty());
    }


    public int[] smallestK1(int[] arr, int k) {
        PriorityQueue<Integer> queue = new PriorityQueue<>();
        for(int i=0;i<arr.length;i++){
            queue.offer(arr[i]);
        }
        int[] ret =new int[k];
        for(int j=0;j<k;j++){
            ret[j]=queue.poll();
        }
        return ret;
    }

    public int[] smallestK(int[] arr, int k) {
        int[] ret =new int[k];
        if(arr==null||k==0){
            return ret;
        }
        Bigheap bigheap =new Bigheap();
        PriorityQueue<Integer> queue = new PriorityQueue<>(bigheap);
        //klogk
        for(int i=0;i<k;i++){
            queue.offer(arr[i]);
        }
        //(N-k)logk
        for(int j=k;j<arr.length;j++){
            int max=queue.peek();
            if(max>arr[j]){
                queue.poll();
                queue.offer(arr[j]);
            }
        }
        //klogk
        for(int s =0;s<k;s++){
            ret[s]=queue.poll();
        }
        return ret;
    }
}
